package com.hd.controller;

import com.hd.mapper.RoleMapper;
import com.hd.pojo.Role;
import com.hd.pojo.User;
import com.hd.service.RoleService;
import com.hd.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by 1 on 2017/11/16.
 */
@Controller
@RequestMapping("/sys")
public class LoginController {

    @Resource
    private UserService userService;



    @PostMapping("/login")
    public String login(String loginName, String password, HttpSession session, Model model){
        User user = userService.searchUserByLoginNameAndPwd(loginName,password);
        if(user!=null) {
            session.setAttribute("loginUser", user);
            return "redirect:/index";
        }
        model.addAttribute("loginErr", "用户名或密码不正确！");
        return "forward:/login.jsp";
    }

}
